package com.example.api;

import com.example.entity.UserEntity;
import com.iogogogo.activity.annotation.Activity;
import com.iogogogo.activity.annotation.WebLog;
import com.iogogogo.activity.util.ExtendBeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by tao.zeng on 2022/6/19.
 */
@Slf4j
@RestController
@RequestMapping("/spel")
public class SpelApi {

    @Activity(source = "{ \"userId\": #user.userId, \"username\": #user.username, \"nickname\": #user.nickname }",
            sourceType = Map.class,
            target = "#newAccountId + ',' + #user.userId", targetType = List.class,
            description = "'「' + #user.nickname + '」将工单指派给「' + #newAccountId + '」'"
    )
    @WebLog
    @PostMapping("/index")
    public Map<String, Object> index(Long newAccountId, @RequestBody UserEntity user) {
        Map<String, Object> map = ExtendBeanUtils.beanToMapForSpringAPI(user);
        map.put("newAccountId", newAccountId);
        return map;
    }
}
